home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 26
/
Cream of the Crop 26.iso
/
program
/
ddj0897.zip
/
DYN401.ZIP
/
utils
/
dos
/
touch.c
< prev
Wrap
C/C++ Source or Header
|
1995-04-18
|
982b
|
77 lines
/*
*
* Copyright 1993 Algorithms Corporation
*
* ALL RIGHTS RESERVED.
*
*
*
*/
#include <stdio.h>
static int touch();
main(argc, argv)
int argc;
char *argv[];
{
int i, err=0;
for (i=1 ; --argc ; ++i)
err |= touch(argv[i]);
return err;
}
static int touch(f)
char *f;
{
FILE *fp;
int c, err=0;
if (NULL != (fp = fopen(f,"r+b"))) {
fseek(fp, 0L, 2);
if (ftell(fp) == 0L) {
fclose(fp);
unlink(f);
if (NULL == (fp = fopen(f, "w"))) {
fprintf(stderr, "touch: can't create %s", f);
err = 1;
}
fclose(fp);
} else {
fseek(fp, 0L, 0);
c = fgetc(fp);
fseek(fp, 0L, 0);
fputc(c, fp);
fclose(fp);
}
} else {
if (NULL == (fp = fopen(f, "w"))) {
fprintf(stderr, "touch: can't create %s", f);
err = 1;
}
fclose(fp);
}
return err;
}
/*
*
* Copyright 1993 Algorithms Corporation
*
* ALL RIGHTS RESERVED.
*
*
*
*/